<template>
	<div class="app-container">
		<el-form ref="finalResultRef" :model="form" :rules="rules" label-width="160px">
			<el-row :gutter="20">
				<el-col :span="21">
					<el-row>
						<el-col :span="24" class="tab-title">
							{{ form.taskName }}评估任务
						</el-col>
					</el-row>
					<el-row :gutter="20">
						<el-col :span="12">
							<el-form-item label="任务编号：" prop="taskNum">
								{{ form.taskNum }}
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="评估人：" prop="">
								{{ form.evaluateUserName }}
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="20">
						<el-col :span="12">
							<el-form-item label="灾害类型：" prop="">
								{{ form.disasterType }}
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="任务地区：" prop="">
								{{ form.taskDistrict }}
							</el-form-item>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="24" class="tab-title">
							数据版本选择
						</el-col>
					</el-row>
					<el-row style="height: 50px;">
						<el-radio-group v-model="form.dataFrom" @change="changeRadio" style="width: 100%;">
							<el-col :span="12">
								<el-radio :label="1">
									<el-form-item label="钻孔数据" label-width="70px" style="margin-bottom: 0px;">
										<el-button v-if="isShowButton" @click="selectSlope" :disabled="isEditSel">选择</el-button>
										<el-link v-else type="primary" :underline="false" @click="selectSlope">{{ form.drillVersion
										}}</el-link>
									</el-form-item>
								</el-radio>
							</el-col>
							<el-col :span="12">
								<el-radio :label="2">
									<el-form-item label="导入钻孔数据" label-width="100px" style="margin-bottom: 0px;">
										<el-button v-if="isShowButton1" @click="handleImport" :disabled="isImport">导入</el-button>
										<el-link v-else type="primary" :underline="false" @click="handleImport">{{ form.drillVersion1
										}}</el-link>
									</el-form-item>
								</el-radio>
							</el-col>
						</el-radio-group>
					</el-row>
					<el-row>
						<el-col :span="24" class="tab-title">
							分析评估
							<el-button type="primary" size="small" @click="replaceModel" style="margin-left: 20px;">更换模型</el-button>
						</el-col>
					</el-row>
					<el-row>
						<el-col :span="12">
							<el-form-item prop="earthquakeGroup" label="设计地震分组：" label-width="120px">
								<el-select v-model="form.earthquakeGroup" placeholder="请选择">
									<el-option v-for="item in [
										{ value: 1, label: '第一组' },
										{ value: 2, label: '第二组' },
										{ value: 3, label: '第三组' },
									]" :key="item.value" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item prop="adjustFactor" label="液化判别深度m：" label-width="150px">
								<el-input v-model="form.adjustFactor" />
							</el-form-item>
						</el-col>
					</el-row>
					<el-row v-if="mapView">
						<p>评估结果：</p>
						<el-table v-loading="loadingTable" :data="resultList" border>
							<el-table-column label="地震动加速度（g）" align="center" prop="earthquakeAcceleration" />
							<el-table-column label="地下水位深度（m）" align="center" prop="liquefactionGroundWaterDepth" />
							<el-table-column label="评估详情" align="center" prop="latitude">
								<template #default="scope">
									<el-button type="text" @click="pgxqView(scope.row)">查看</el-button>
								</template>
							</el-table-column>
							<el-table-column label="地图查看结果" align="center" prop="geotechnicalDesignation">
								<template #default="scope">
									<el-button type="text" @click="mapViewResult(scope.row)" v-if="scope.row.canShow == '1'">查看</el-button>
								</template>
							</el-table-column>

						</el-table>
					</el-row>
				</el-col>
				<el-col :span="3">
					<el-space direction="vertical" alignment="start">
						<el-button type="primary" @click="saveMiddleResult">存为中间结果</el-button>
						<el-button type="primary" v-if="!mapView" @click="calculation">评估计算</el-button>
						<el-button type="primary" v-else @click="calculation">重新评估计算</el-button>
					</el-space>
				</el-col>
			</el-row>
		</el-form>

		<!-- 打开坡度数据选择对话框 -->
		<el-dialog :title="title" v-model="openSlope" width="1000px" append-to-body>
			<p></p>
			<el-form :model="queryParams" ref="querySelRef" :inline="true" v-show="showSearch" label-width="120px">
				<el-form-item label="版本号" prop="versionCode">
					<el-input v-model="queryParamsSel.versionCode" clearable />
				</el-form-item>
				<el-form-item label="上传人" prop="uploadUser">
					<el-input v-model="queryParamsSel.uploadUser" clearable />
				</el-form-item>
				<el-form-item label="上传日期">
					<el-col :span="10">
						<el-date-picker type="date" placeholder="选择日期" value-format="YYYY-MM-DD"
							v-model="queryParamsSel.uploadStartTime" style="width: 100%;" :disabled-date="startDisabledDate1"></el-date-picker>
					</el-col>
					<el-col class="line" :span="1">至</el-col>
					<el-col :span="10">
						<el-date-picker type="date" placeholder="选择日期" value-format="YYYY-MM-DD"
							v-model="queryParamsSel.uploadEndTime" style="width: 100%;" :disabled-date="endDisabledDate1"></el-date-picker>
					</el-col>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="Search" @click="handleQuerySel">搜索</el-button>
					<el-button icon="Refresh" @click="resetQuerySel">重置</el-button>
				</el-form-item>
			</el-form>
			<el-table v-loading="loadingSel" ref="tableRef" :data="slopeDataList">
				<el-table-column type="expand" width="1">
					<template #default="props">
						<div class="expandTable">
							<h3>更多信息</h3>
							<p>数据名称: {{ props.row.dataName }}</p>
							<p>版本说明: {{ props.row.versionDesc }}（此处是版本说明，<span style="color:red">限制300字以内</span> ）</p>
							<p>数据说明: {{ props.row.dataDesc }}（此处是数据说明，<span style="color:red">限制300字以内</span> ）</p>
							<!--<p v-if="props.row.updateDesc">更新说明: {{ props.row.dataType }}</p>
            <p>使用系统: {{ props.row.useThisSystems }}
              <el-tooltip class="box-item" content="Right Center prompts info" placement="right">
                <el-tag>系统使用说明</el-tag>
              </el-tooltip>
            </p>
            <p>数据文件:
              <template v-for="item in props.row.dataFileList">
                <u style="color:#107ce5;cursor: pointer;" @click="handleDownload(item)">{{ item.name }}</u><br />
              </template>
            </p>
            <p>附件:
              <template v-for="item in props.row.attachmentList">
                <u style="color:#107ce5;cursor: pointer;" @click="handleDownload(item)">{{ item.name }}</u><br />
              </template>
            </p>-->
						</div>
					</template>
				</el-table-column>
				<el-table-column label="版本日期" align="center" prop="versionTime">
					<!--<template #default="scope">
						<el-button type="text" @click="edit(scope.row)">{{ scope.row.modelName }}
						</el-button>
					</template>-->
				</el-table-column>
				<el-table-column label="版本号" align="center" prop="versionCode" width="200" />
				<el-table-column label="版本级别（版本范围）" align="center" prop="dataRange" width="220" />
				<el-table-column label="上传日期" align="center" prop="uploadTime" />
				<el-table-column label="上传人" align="center" prop="uploadUser" />
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
					<template #default="scope">
						<el-button type="text" @click="handleMore(scope.row)">更多信息</el-button>
						<el-button type="text" @click="handleSelect(scope.row)">选择</el-button>
					</template>
				</el-table-column>
			</el-table>

			<pagination v-show="totalSel > 0" :total="totalSel" v-model:page="queryParamsSel.page"
				v-model:limit="queryParamsSel.rows" @pagination="getSlopeDataList" />

			<template #footer>
				<div class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
				</div>
			</template>
		</el-dialog>
		<el-dialog title="评估详情查看" v-model="open" width="1300px" append-to-body>
			<p></p>
			<el-row :gutter="10" class="mb8">
				<el-col :span="1.5">
					<el-button type="primary" @click="handleExport">导出</el-button>
				</el-col>

			</el-row>
			<el-table :data="pgxqDataList" border :span-method="objectSpanMethod">

				<el-table-column label="钻孔编号" align="center" prop="drillCode" width="100" />
				<el-table-column label="钻孔经度（°）" align="center" prop="longitude" width="120" />

				<el-table-column label="钻孔纬度（°）" align="center" prop="latitude" width="120" />
				<el-table-column label="液化判别地下水位深度dw(m)" align="center" prop="liquefactionGroundWaterDepth" width="120" />
				<el-table-column label="调整系数（β）" align="center" prop="adjustFactor" width="120" />
				<el-table-column label="地层编号" align="center" prop="stratumNum" width="120" />
				<el-table-column label="层底深度" align="center" prop="stratumDepth" width="120" />
				<el-table-column label="分层厚度" align="center" prop="layerThickness" width="120" />
				<el-table-column label="土层名称" align="center" prop="geotechnicalName" width="120" />
				<el-table-column label="标贯点顶深（m）" align="center" prop="fullboreTopDepth" width="120" />
				<el-table-column label="标贯点底深（m）" align="center" prop="fullboreBottomDepth" width="120" />
				<el-table-column label="标贯点深度ds（m）" align="center" prop="ds" width="120" />
				<el-table-column label="标贯点所代表土层的中点深度（m）" align="center" prop="fullboreSoilDepth" width="120" />
				<el-table-column label="标贯点代表的土层厚度di（m）" align="center" prop="fullboreSoilThickness" width="120" />
				<el-table-column label="黏粒含量ρc（%）" align="center" prop="clayContent" width="120" />
				<el-table-column label="实际锤击数N（击）" align="center" prop="actualBlowsNumber" width="120" />
				<el-table-column label="标准贯人锤击数临界值Ncr(击)" align="center" prop="ncr" width="120" />
				<el-table-column label="N/Ncr" align="center" prop="specificValue" />
				<el-table-column label="液化判别" align="center" prop="liquefactionDifferentiate" width="120" />
				<el-table-column label="Wi值" align="center" prop="wi" width="120" />
				<el-table-column label="液化指数IEI" align="center" prop="ei" width="120" />
				<el-table-column label="液化指数IE" align="center" prop="dei" width="120" />
				<el-table-column label="液化等级" align="center" prop="sandLevel" width="120" />
			</el-table>

			<template #footer>
				<div class="dialog-footer">
					<el-button @click="cancelView">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
		<!-- 导入对话框 -->
		<el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
			<p></p>
			<el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
				:disabled="upload.isUploading" :before-upload="handleFileBeforeUpload" :on-progress="handleFileUploadProgress"
				:on-error="handleFileUploadError" :on-success="handleFileSuccess" :auto-upload="false" :data="dataFile" drag>
				<el-icon class="el-icon--upload">
					<upload-filled />
				</el-icon>
				<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
				<template #tip>
					<div class="el-upload__tip text-center">
						<span>仅允许导入xls、xlsx格式文件。</span>
						<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
							@click="importTemplate('砂土液化导入模板.xls')">下载模板</el-link>
					</div>
				</template>
			</el-upload>
			<template #footer>
				<div class="dialog-footer">
					<el-button type="primary" @click="submitFileForm">确 定</el-button>
					<el-button @click="upload.open = false">取 消</el-button>
				</div>
			</template>
		</el-dialog>
		<el-dialog v-model="openAnalysis" title="模型选择" width="600px" append-to-body>
			<p></p>
			<el-tabs v-model="activeNameModel" type="card" @tab-click="handleModelClick">
				<el-tab-pane label="场地评估-标贯法" name="first">
					<el-row>
						<el-col :span="6" :offset="1">
							<el-radio-group v-model="radio">
								<el-radio :label="1">饱和砂土或粉土<el-link type="primary" :underline="false" @click="formulaDesc1"
										style="font-size:14px;margin-left: 30px;">公式说明</el-link></el-radio>
								<el-radio :label="2">饱和黄土<el-link type="primary" :underline="false" @click="formulaDesc2"
										style="font-size:14px;margin-left: 72px;">公式说明</el-link></el-radio>
							</el-radio-group>
						</el-col>
					</el-row>
					<el-row>
						<el-col :offset='1' style="margin-top: 10px">所需数据为钻孔。</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="场地评估-液化指数法" name="second">
					<el-row>
						<el-col :span="6" :offset="1">
							<el-radio-group v-model="radio">
								<el-radio :label="3">饱和砂土或粉土<el-link type="primary" :underline="false" @click="formulaDesc3"
										style="font-size:14px;margin-left: 30px;">公式说明</el-link></el-radio>
								<el-radio :label="4">饱和黄土<el-link type="primary" :underline="false" @click="formulaDesc4"
										style="font-size:14px;margin-left: 72px;">公式说明</el-link></el-radio>
							</el-radio-group>
						</el-col>
					</el-row>
					<el-row>
						<el-col :offset='1' style="margin-top: 10px">所需数据为钻孔。</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="区域评估-层次分析法" name="third">
					<el-row>
						<el-col :span="6" :offset="1">
							<el-radio v-model="radio" label="5">层次分析法<el-link type="primary" :underline="false" @click="formulaDesc5"
									style="font-size:14px;margin-left: 30px;">公式说明</el-link></el-radio>
						</el-col>
					</el-row>
					<el-row>
						<el-col :offset='1' style="margin-top: 10px">所需数据包括高程、地层岩性、水系、地震动峰值加速度。</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="confirm">确 定</el-button>
				</span>
			</template>
		</el-dialog>
		<el-dialog title="公式说明" v-model="openFormula1" width="900px" append-to-body>
			<p></p>
			<Formula1></Formula1>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openFormula1 = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
		<el-dialog title="公式说明" v-model="openFormula2" width="900px" append-to-body>
			<p></p>
			<Formula2></Formula2>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openFormula2 = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
		<el-dialog title="公式说明" v-model="openFormula3" width="900px" append-to-body>
			<p></p>
			<Formula3></Formula3>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openFormula3 = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
		<el-dialog title="公式说明" v-model="openFormula5" width="900px" append-to-body>
			<p></p>
			<Formula5></Formula5>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openFormula5 = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
		<!--空间分析-->
		<Spatialanalyst v-if="spatialanalystBool" :open="spatialanalystBool" :sandliquidAssessList="sandliquidAssessList"
			@close="spatialanalystClose"></Spatialanalyst>
	</div>
</template>

<script setup name="indexAssess2Form">
import { getTaskModelDetail, saveAsMiddleResult, getSlopeData, count, getEvaluateResult, selectVersionCode, getDetails, replaceFinalModel } from "@/api/sandliquidAssess/indexAssess1";
import useUserStore from '@/store/modules/user'
import { getToken } from "@/utils/auth";
import Formula1 from "./formula1.vue"
import Formula2 from "./formula2.vue"
import Formula3 from "./formula3.vue"
import Formula5 from "./formula5.vue"
import Spatialanalyst from '@/map/components/spatialanalyst/index.vue'
import { ElLoading } from 'element-plus';

const userStore = useUserStore();
const route = useRoute();
const router = useRouter();
const openSlope = ref(false);
const { proxy } = getCurrentInstance();
const activeNameModel = ref("first");
const modelName = ref("");
const modelLabel = ref("");
const slopeDataList = ref([]);
const resultList = ref([]);
const isShowButton = ref(true);
const isShowButton1 = ref(true);
const mapView = ref(false);
const pgxqDataList = ref([]);
const isEditSel = ref(true);
const isImport = ref(true);
const openAnalysis = ref(false);
const radio = ref(1);
const openFormula1 = ref(false);
const openFormula2 = ref(false);
const openFormula3 = ref(false);
const openFormula5 = ref(false);
const spatialanalystBool = ref(false);//是否开启空间分析
const sandliquidAssessList = ref(false);//用于空间分析的砂土液化数据
const loading = ref(false);
const loadingTable = ref(true);
const open = ref(false);
const loadingSel = ref(true);
const showSearch = ref(true);
const totalSel = ref(0);
const title = ref("");
const earthquakeAcceleration = ref("");
const liquefactionGroundWaterDepth = ref("");

// 保留三位小数
const positive3decimals = (rule, value, callback) => {
	value = String(value)
	if (isNaN(value) || !value) {
		return callback(new Error());
	}
	var re = /^([0-9]+[\d]*(.[0-9]{3}))$/;
	if (!re.test(value)) {
		callback(new Error());
	} else {
		callback();
	}
}

// 保留两位小数
const positive2decimals = (rule, value, callback) => {
	value = String(value)
	if (isNaN(value) || !value) {
		return callback(new Error());
	}
	var re = /^([0-9]+[\d]*(.[0-9]{2}))$/;
	if (!re.test(value)) {
		callback(new Error());
	} else {
		callback();
	}
}

// (0,10]整数
const positive0_10integer = (rule, value, callback) => {
	value = String(value)
	if (isNaN(value) || !value) {
		return callback(new Error());
	}
	var re = /^([1-9]|10)$/;
	if (!re.test(value)) {
		callback(new Error());
	} else {
		callback();
	}
}

// [3,5]整数
const positive3_5integer = (rule, value, callback) => {
	value = String(value)
	if (isNaN(value) || !value) {
		return callback(new Error());
	}
	var re = /^([3-5])$/;
	if (!re.test(value)) {
		callback(new Error());
	} else {
		callback();
	}
}
const data = reactive({
	form: {},
	queryParams: {
		page: 1,
		rows: 10,
	},
	queryParamsSel: {
		page: 1,
		rows: 10,
	},
	rules: {
		taskCode: [{
			required: true,
			message: "任务编号不能为空",
			trigger: "blur"
		}],
		modelName: [{
			required: true,
			message: "模型名称不能为空",
			trigger: "blur"
		}],
		province: [{
			required: true,
			message: "省不能为空",
			trigger: "blur"
		}],
		provinceId: [{
			required: true,
			message: "省不能为空",
			trigger: "change"
		}],
		city: [{
			required: true,
			message: "市不能为空",
			trigger: "change"
		}],
		cityId: [{
			required: false,
			message: "市不能为空",
			trigger: "change"
		}],
		area: [{
			required: true,
			message: "区/县不能为空",
			trigger: "blur"
		}],
		areaId: [{
			required: true,
			message: "区/县 不能为空",
			trigger: "blur"
		}],
		smrsNumber1: [{
			required: true,
			message: "保留三位小数",
			trigger: "blur",
			validator: positive3decimals
		}],
		smrsNumber2: [{
			required: true,
			message: "保留两位小数",
			trigger: "blur",
			validator: positive2decimals
		}],
		deathNumber: [{
			required: true,
			message: "（0,10]之间的整数数",
			trigger: "blur",
			validator: positive0_10integer
		}],
		injuries: [{
			required: true,
			message: "[3,5]之间的整数",
			trigger: "blur",
			validator: positive3_5integer
		}],

	}
});

const { queryParams, queryParamsSel, form, rules } = toRefs(data);
/*** 用户导入参数 */
const upload = reactive({
	open: false,
	title: "",
	isUploading: false,
	headers: {
		token: "token " + getToken()
	},
	url: import.meta.env.VITE_APP_BASE_API + "/sand/importDrillData/" + route.query.taskId + "/" + form.value.drillVersion1
});


const startDisabledDate1 = (time) => {
  if (queryParamsSel.value.uploadEndTime) {
    return time.getTime() > new Date(queryParamsSel.value.uploadEndTime).getTime();
  }
  return false;
};
const endDisabledDate1 = (time) => {
  if (queryParamsSel.value.uploadStartTime) {
    return time.getTime() < new Date(queryParamsSel.value.uploadStartTime).getTime();
  }
  return false;
};

// 监听开始时间和结束时间的变化，更新对应的 disabledDate 函数
watch(queryParamsSel.value.uploadStartTime, (newVal) => {
  // 当开始时间改变时，更新结束时间的选择范围
  endDisabledDate1(newVal);
});

watch(queryParamsSel.value.uploadEndTime, (newVal) => {
  // 当结束时间改变时，更新开始时间的选择范围
  startDisabledDate1(newVal);
});

/** 获取模型详情 */
function getTaskModel() {
	const loading = ElLoading.service({
		lock: true,
		text: '加载中...',
		background: 'rgba(0, 0, 0, 0.7)',
	})
	const { taskId, dmslId } = route.query
	let params = { taskId, dmslId, algorithmType: '2'}
	getTaskModelDetail(params).then(response => {
		loading.close()
		form.value = response.data.modelSandLiquefaction;
		if (response.data.modelSandLiquefaction.dataFrom == 1) {
			isShowButton.value = false
		} else if (response.data.modelSandLiquefaction.dataFrom == 2) {
			isShowButton1.value = false
			form.value.drillVersion1 = form.value.drillVersion
		}
		loading.close()
		loadingTable.value = false;
		mapView.value = true;
		resultList.value = response.data.resultSandLiquefaction;
		// if (form.value.dmslId) {
		// 	mapView.value = true;
		// 	getEvaluateResult({
		// 		"dmslId": form.value.dmslId,
		// 		"taskId": route.query.taskId,
		// 		"taskDistrict": route.query.taskDistrict
		// 		}).then(response => {
		// 			resultList.value = response.data;
		// 			loadingTable.value = false;
		// 		});
		// 	}
	});
}
// 取消按钮
function cancel() {
	openSlope.value = false;
}
/** 搜索按钮操作 */
function handleQuerySel() {
	queryParamsSel.value.page = 1;
	getSlopeDataList();
}
function resetQuerySel() {
	queryParamsSel.value.uploadStartTime = "";
	queryParamsSel.value.uploadEndTime = "";
	proxy.resetForm("querySelRef");
	handleQuerySel();
}
//获取坡度数据版本
function getSlopeDataList() {
	loadingSel.value = true;
	var province = route.query.taskDistrict;
	getSlopeData({
		...queryParamsSel.value,
		"typeCode": "y02ckxx,y04dcyxfc,y05bgzy06jqbscz,y10tgsycs",
		"province": province
	}).then(response => {
		loadingSel.value = false;
		slopeDataList.value = response.data.list;
		totalSel.value = response.data.total;
	});
}
//存为中间结果
function saveMiddleResult() {
	saveAsMiddleResult({
		"taskId": route.query.taskId,
		//"versionCode": drillVersion.value
		"algorithmType": "2"
	}).then(response => {
		proxy.$modal.msgSuccess(response.data);
	});
}
//更换模型
function replaceModel() {
	var flag = "";
	proxy.$confirm('更换模型前，请选择是否将当前结果存为中间结果？选择“否”当前结果将被覆盖。', '系统提示',
		{ confirmButtonText: '是', cancelButtonText: '否', type: 'warning' }).then(function () {
		}).then(() => {
			flag = "1"
			replaceFinalModel({ "dmslId": form.value.dmslId, "flag": flag, "taskId": form.value.taskId }).then(response => {
				openAnalysis.value = true;
			});
		}).catch(() => {
			flag = "0"
			replaceFinalModel({ "dmslId": form.value.dmslId, "flag": flag, "taskId": form.value.taskId }).then(response => {
				openAnalysis.value = true;
			});
		});
}
function confirm() {
	proxy.$tab.closePage(router.currentRoute.value);
	if (radio.value == "1") {
		//饱和砂土或粉土标贯法
		router.push({
			path: "/stAnalysisAssess/indexAssess1",
			query: {
				taskId: route.query.taskId,
				taskDistrict: route.query.taskDistrict,
				type: "1",
				metaTitle: "饱和砂土或粉土标贯法"
			}
		})
	}
	if (radio.value == "2") {
		//饱和黄土标贯法
		router.push({
			path: "/stAnalysisAssess/indexAssess1",
			query: {
				taskId: route.query.taskId,
				taskDistrict: route.query.taskDistrict,
				type: "2",
				metaTitle: "饱和黄土标贯法"
			}
		})
	}
	if (radio.value == "3") {
		//饱和砂土或粉土液化指数法
		router.push({
			path: "/stAnalysisAssess/indexAssess2",
			query: {
				taskId: route.query.taskId,
				taskDistrict: route.query.taskDistrict,
				type: "3",
				metaTitle: "饱和砂土或粉土液化指数法"
			}
		})
	}
	if (radio.value == "4") {
		//饱和黄土液化指数法
		router.push({
			path: "/stAnalysisAssess/indexAssess2",
			query: {
				taskId: route.query.taskId,
				taskDistrict: route.query.taskDistrict,
				type: "4",
				metaTitle: "饱和黄土液化指数法"
			}
		})
	}
	if (radio.value == "5") {
		//层次分析法
		router.push({
			path: "/stAnalysisAssess/indexAssess3",
			query: {
				taskId: route.query.taskId,
				taskDistrict: route.query.taskDistrict,
				type: "5",
				metaTitle: "层次分析法"
			}
		})
	}
	openAnalysis.value = false;
}
function formulaDesc1() {
	openFormula1.value = true;
}
function formulaDesc2() {
	openFormula2.value = true;
}
function formulaDesc3() {
	openFormula3.value = true;
}
function formulaDesc4() {
	openFormula3.value = true;
}
function formulaDesc5() {
	openFormula5.value = true;
}
//评估计算
function calculation() {
	const loading = ElLoading.service({
		lock: true,
		text: '计算中...',
		background: 'rgba(0, 0, 0, 0.7)',
	})
	spatialanalystBool.value = false;//关闭空间分析
	sandliquidAssessList.value = {};
	count({
		"versionCode": form.value.dataFrom == 1 ? form.value.drillVersion : form.value.drillVersion1,
		"taskId": route.query.taskId,
		"algorithmType": "2", //1:标贯法；2：液化指数法；3：层次分析法
		"operands": route.query.type == '3' ? "1" : "2", //1：饱和砂土或粉土；2：饱和黄土
		"modelType": form.value.modelType, //1:建筑抗震设计规范;2:区域性地震安全性评价技术规范
		"earthquakeGroup": form.value.earthquakeGroup, //1:第一组；2：第二组，3：第三组
		"adjustFactor": form.value.adjustFactor, //β0--调整系数
		"dataFrom": form.value.dataFrom, //1使用选择的钻孔数据、2：使用上传的钻孔数据
		resultStatus: route.query.dmslId ? '1' : '2', // 最终结果2，中间结果1
		dmslId: form.value.dmslId || ''
	}).then(response => {
		form.value.dmslId = response.data;
		proxy.$modal.msgSuccess(response.message);
		getEvaluateResult({
			"dmslId": form.value.dmslId,
			"taskId": route.query.taskId,
			"taskDistrict": route.query.taskDistrict
		}).then(response => {
			mapView.value = true;
			resultList.value = response.data;
			if (resultList.value.length > 0) {
				spatialanalystBool.value = true;//开启空间分析--根据是否砂土液化点数据生成等值面
				sandliquidAssessList.value = {
					type: "2", //1:标贯法；2：液化指数法；3：层次分析法
					list: resultList.value,
					dmslId: form.value.dmslId
				};
			} else {
				proxy.$modal.msgWarning("无评估结果");
			}
			loading.close()
		});
	}).catch(() => {
		proxy.$modal.msgError("评估失败");
		loading.close()
	});
}
//完成空间分析
function spatialanalystClose() {
	spatialanalystBool.value = false;//关闭空间分析
}
// 更多数据
function handleMore(row) {
	proxy.$refs['tableRef'].toggleRowExpansion(row);
}
// 选择版本
function handleSelect(row) {
	isShowButton.value = false;
	form.value.drillVersion = row.versionCode;

	selectVersionCode({
		"versionCode": row.versionCode,
		"taskId": route.query.taskId,
		//			"disasterType": "3"
	}).then(response => {
		openSlope.value = false;
		//proxy.$modal.msgSuccess(response.message);
	});
}
//坡度数据选择
function selectSlope() {
	openSlope.value = true;
	getSlopeDataList();
}
//评估详情查看
function pgxqView(row) {
	open.value = true;
	earthquakeAcceleration.value = row.earthquakeAcceleration
	liquefactionGroundWaterDepth.value = row.liquefactionGroundWaterDepth
	getDetails({
		"dmslId": form.value.dmslId,
		"earthquakeAcceleration": row.earthquakeAcceleration,
		"liquefactionGroundWaterDepth": row.liquefactionGroundWaterDepth,
	}).then(response => {
		pgxqDataList.value = response.data
	});
}
//地图查看结果
function mapViewResult(row) {
	router.push({
		path: "/stAnalysisAssess/indexModelMapSelect",
		query: {
			taskId: route.query.taskId,
			taskDistrict: 'row.taskDistrict',
			modelLabel: '层次分析模型',
			modelType: route.query.type,
			metaTitle: "评估结果查看",
			dmslId: form.value.dmslId,//模型ID
			earthquakeAcceleration: row.earthquakeAcceleration,//地震动加速度
			liquefactionGroundWaterDepth: row.liquefactionGroundWaterDepth,//地下水位深度（液化判别地下水位深度dw(m)）
			algorithmType: "2", //1:标贯法；2：液化指数法；3：层次分析法
		}
	})
}
//导出
function handleExport() {
	//debugger
	proxy.download("/sand/export", {
		dmslId: form.value.dmslId,
		earthquakeAcceleration: earthquakeAcceleration.value,
		liquefactionGroundWaterDepth: liquefactionGroundWaterDepth.value,
		flag: "1"
	}, `评估详情数据_${new Date().getTime()}.xls`)
	//location.herf = import.meta.env.VITE_APP_BASE_API + "/sand/export?dmslId="+form.value.dmslId+"&earthquakeAcceleration="+earthquakeAcceleration.value
	//+"&liquefactionGroundWaterDepth="+liquefactionGroundWaterDepth.value+"&flag=1"
}
//关闭
function cancelView() {
	open.value = false
}
function objectSpanMethod({ row, column, rowIndex, columnIndex }) {
	if (columnIndex === 0) {
		const _row = setTable(pgxqDataList.value).one[rowIndex];
		const _col = _row > 0 ? 1 : 0;
		return {
			rowspan: _row,
			colspan: _col
		};
	}
	if (columnIndex === 1) {
		const _row = setTable(pgxqDataList.value).two[rowIndex];
		const _col = _row > 0 ? 1 : 0;
		return {
			rowspan: _row,
			colspan: _col
		};
	}
	if (columnIndex === 2) {
		const _row = setTable(pgxqDataList.value).three[rowIndex];
		const _col = _row > 0 ? 1 : 0;
		return {
			rowspan: _row,
			colspan: _col
		};
	}
	if (columnIndex === 21) {
		const _row = setTable(pgxqDataList.value).four[rowIndex];
		const _col = _row > 0 ? 1 : 0;
		return {
			rowspan: _row,
			colspan: _col
		};
	}
	if (columnIndex === 22) {
		// const _row = setTable(pgxqDataList.value).five[rowIndex];
		const _row = setSpan(pgxqDataList.value)[rowIndex];
		const _col = _row > 0 ? 1 : 0;
		return {
			rowspan: _row,
			colspan: _col
		};
	}
}
const setSpan = (tableData) => {
	let rowSpan = []
	tableData.map((item, index) => {
		if(rowSpan[index] || rowSpan[index]==0){
			return
		}
		rowSpan.push(item.num)
		if (item.num > 0) {
			for (let i = index + 1; i < item.num + index; i++) {
				rowSpan[i] = 0
			}
		}
	})
	return rowSpan
}
function setTable(tableData) {
	let spanOneArr = [],
		spanTwoArr = [],
		spanThreeArr = [],
		spanFourArr = [],
		spanFiveArr = [],
		concatOne = 0,
		concatTwo = 0,
		concatThree = 0,
		concatFour = 0,
		concatFive = 0;
	tableData.forEach((item, index) => {
		if (index === 0) {
			spanOneArr.push(1);
			spanTwoArr.push(1);
			spanThreeArr.push(1);
			spanFourArr.push(1);
			spanFiveArr.push(1);
		} else {
			if (item.drillCode === tableData[index - 1].drillCode) {
				//第一列需合并相同内容的判断条件
				spanOneArr[concatOne] += 1;
				spanOneArr.push(0);
			} else {
				spanOneArr.push(1);
				concatOne = index;
			}

			if (item.longitude === tableData[index - 1].longitude) {
				//第二列和需合并相同内容的判断条件
				spanTwoArr[concatTwo] += 1;
				spanTwoArr.push(0);
			} else {
				spanTwoArr.push(1);
				concatTwo = index;
			}

			if (item.latitude === tableData[index - 1].latitude) {
				//第三列和需合并相同内容的判断条件
				spanThreeArr[concatThree] += 1;
				spanThreeArr.push(0);
			} else {
				spanThreeArr.push(1);
				concatThree = index;
			}

			if (item.dei === tableData[index - 1].dei && index % item.num != 0) {
				//第21列和需合并相同内容的判断条件
				spanFourArr[concatFour] += 1;
				spanFourArr.push(0);
			} else {
				spanFourArr.push(1);
				concatFour = index;
			}
			if (item.sandLevel === tableData[index - 1].sandLevel && index % item.num != 0) {
				//第22列和需合并相同内容的判断条件
				spanFiveArr[concatFive] += 1;
				spanFiveArr.push(0);
			} else {
				spanFiveArr.push(1);
				concatFive = index;
			}
		}
	});
	return {
		one: spanOneArr,
		two: spanTwoArr,
		three: spanThreeArr,
		four: spanFourArr,
		five: spanFiveArr,
	};
}
// 模板下载
function importTemplate(name) {
	proxy.download("/base/product/downloadExcel", {
		fileName: name
	}, name);
};
/** 提交上传文件 */
function submitFileForm() {
	proxy.$refs["uploadRef"].submit();
};

/** 打开导入表弹窗 */
function handleImport() {
	upload.title = "导入";
	upload.open = true;
}
/**文件上传前处理 */
function handleFileBeforeUpload(file) {
	proxy.$modal.loading("正在导入文件，请稍候...");
	return true
}

/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
	upload.isUploading = true;
};
// 上传失败
function handleFileUploadError(err) {
	proxy.$modal.closeLoading();
	proxy.$modal.msgError("导入文件失败");
}
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
	upload.open = false;
	upload.isUploading = false;
	proxy.$modal.closeLoading();
	proxy.$refs["uploadRef"].handleRemove(file);
	proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 0 0;'>" + response.message + "</div>", "导入结果", {
		dangerouslyUseHTMLString: true
	});
	form.value.drillVersion1 = response.data;
	if(response.code==200){
			isShowButton1.value = false;
	}
	//		getPrefectureResult(dataFile.taskCode).then(response => {
	//			prefectureResult.value = response.data;
	//		});
	//		getResult(dataFile.taskCode).then(response => {
	//			Result.value = response.data;
	//		});
};
function changeRadio(value) {
	if (value == 1) {
		isEditSel.value = false;
		isImport.value = true;
	} else {
		isEditSel.value = true;
		isImport.value = false;
	}
}
//切换模型标签页
function handleModelClick(tab, event) {
	if (tab.props.name == "first") {
		radio.value = 1;
	} else if (tab.props.name == "second") {
		radio.value = 3;
	} else if (tab.props.name == "third") {
		radio.value = "5";
	}
	modelName.value = tab.props.name;
	modelLabel.value = tab.props.label;
}

getTaskModel();
</script>
<style lang="scss" scoped>
@import '@/assets/styles/variables.module.scss';
.tab-title {
	font-size: 16px;
	font-weight: bold;
	border-left: 4px solid #0D9AFF;
	font-family: PingFangSC-Medium;
	padding-left: 10px;
	// margin-bottom: 20px;
	margin: 10px 0 20px;
}

.line {
	text-align: center;
}

table td {
	border: 1px solid #c6c6c6;
}

:deep(.el-table td.el-table__cell) {
	border-bottom: 1px solid #ebeef5 !important;
	border-right: 1px solid #ebeef5 !important;
}

// :deep(.el-table td.el-table__cell) {
//   border-bottom: 1px solid #ebeef5 !important;
//   border-right: 1px solid #ebeef5 !important;
//   border-left: 1px solid #ebeef5 !important;
// }
form{
	width: 75%;
	margin: 0 auto;
}
:deep(.el-space){
	.el-space__item{
		width: 100%;
	}
}
</style>